import { _decorator, Component, RenderTexture, Camera, view, UITransform } from 'cc';
import { EDITOR } from 'cc/env';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('Adapter')
@executeInEditMode
export class Adapter extends Component {
    @property([RenderTexture])
    protected rts: RenderTexture[] = [];

    @property({slide:true,step:0.05,min:0.1,max:1.0})
    get rtScale(){
        return this._rtScale;
    }
    set rtScale(v){
         this._rtScale = v;
         this.resetRT();
    }

    private _rtScale:number = 1.0;

    onEnable() {
        this.resetRT();
    }

    resetRT(){
        const size = EDITOR ? view.getDesignResolutionSize() : this.node.getComponent(UITransform).contentSize;
    
        for (let i = 0; i < this.rts.length; ++i) {
            let rt = this.rts[i];
            rt.resize(size.width * this.rtScale, size.height * this.rtScale);
        }
    }
}

